package ua.kpi_java_training.evgeniygusar.module2;

public class PoolInAction {
    public AllPredators predatorsObject = new AllPredators();
    public int current_step=0;
    public AllVictims victimsObject = new AllVictims();

    public int total_number_of_borning_victims = 1;
    public int total_number_of_borning_predators = 1;

    public void startAction(int current_step){
        this.current_step = current_step;
        displayNextStep(current_step);

        if (victimsObject.numbersOfVictims() != 0) {
            victimsObject.victimsMoving();
            victimsObject.displayVictimsMoving();
            predatorsObject.predatorsMoving();
        }

        checkVictimBorning();
        checkPredatorBorning();
    }

    void displayNextStep(int current_step) {
        System.out.println("-----------------------------");
        System.out.println("Step " + current_step);
    }

    void checkVictimBorning() {
        if (current_step%victimsObject.getVictimBirthCycle()==0) {
            victimsObject.addVictim();
            total_number_of_borning_victims++;
            System.out.println("New victim is borning!");
            System.out.print("Victim " + (victimsObject.numbersOfVictims()) + ": ");
            victimsObject.getVictim(victimsObject.numbersOfVictims() - 1).showCoordinats();
        }
    }

    void checkPredatorBorning() {
        if (current_step%predatorsObject.getPredatorBirthCycle()==0) {
            predatorsObject.addPredator();
            total_number_of_borning_predators++;
            System.out.println("New predator is borning!");
            System.out.print("Predator " + (predatorsObject.numbersOfPredators()) + ": ");
            predatorsObject.getPredator(predatorsObject.numbersOfPredators() - 1).showCoordinats();
        }
    }

    void showStatistics() {
        System.out.println("-----------------------------");
        System.out.println("Total number of borning victims: " + total_number_of_borning_victims);
        System.out.println("Total number of eated victims by predator: " + predatorsObject.getTotalNumberOfEatedVictims());
        System.out.println("Number victims that still living: " + victimsObject.numbersOfVictims());
        System.out.println("Total number of borning predators: " + total_number_of_borning_predators);
    }
}
